#include <bits/stdc++.h>

using namespace std;

int va(string & s, vector<int> & a){
    int cnt = 0;
    for (int i = 0; i < a.size(); ++i){
        int f = 0;
        for (int j = i - 1; j >= 0; --j){
            if (s[i] == s[j]){
                if (a[i] == a[j]){
                    f = a[i];
                }
                break;
            }
        }
        cnt += f;
    }
    return cnt;
}

int ans = 0;
void dfs(int i, string s, int n, vector<int> & a){
    if (i == n){
        ans = max(va(s, a), ans);
        return;
    }
    s[i] = '0';
    dfs(i + 1, s, n, a);
    s[i] = ' ';
    s[i] = '1';
    dfs(i + 1, s, n, a);
    s[i] = ' ';
    return;
}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    int t;
    cin >> t;

    while (t--){
        int n;
        cin >> n;

        vector<int> a;
        for (int i = 0; i < n; ++i){
            int x;
            cin >> x;
            a.push_back(x);
        }

        ans = 0;
        dfs(0, "                                ", n, a);
        cout << ans << endl;
    }
    return 0;
}